package com.sqs.controller;


import com.sqs.constant.ResultConstant;
import com.sqs.context.BaseContext;
import com.sqs.dto.RepositoryUpdateDTO;
import com.sqs.result.Result;
import com.sqs.service.IRepositoryService;
import com.sqs.vo.RepositoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/repository")
public class RepositoryController {

    @Autowired
    private IRepositoryService iRepositoryService;

    /**
     * 新增知识库
     * @param name
     * @return
     * */
    @PostMapping
    public Result<RepositoryVO> repositoryInsert(String name){
        log.info("新增知识库：{}", name);
        return Result.success(ResultConstant.ADD_SUCCESS, iRepositoryService.repositoryInsert(name));
    }

    /**
     * 查询该用户所有的知识库
     * @return
     */
    @GetMapping
    public Result<List<RepositoryVO>> repositoriesSelect(){
        log.info("查询该用户所有的知识库:{}", BaseContext.getCurrentId());
        List<RepositoryVO> repositories = iRepositoryService.repositoriesSelect();
        return Result.success(ResultConstant.SEARCH_SUCCESS, repositories);
    }

    /**
     * 修改知识库信息
     * @param repositoryUpdateDTO
     * @return
     * */
    @PutMapping
    public Result repositoryUpdate(RepositoryUpdateDTO repositoryUpdateDTO){
        log.info("修改知识库信息:{}", repositoryUpdateDTO);
        iRepositoryService.repositoryUpdate(repositoryUpdateDTO);
        return Result.success(ResultConstant.UPDATE_SUCCESS);
    }

    /**
     * 删除知识库
     * @param id
     * @return
     * */
    @DeleteMapping
    public Result deleteRepository(Long id){
        log.info("删除知识库：{}", id);
        iRepositoryService.repositoryDelete(id);
        return Result.success(ResultConstant.DELETE_SUCCESS);
    }

}
